package com.cadre.web.controller.officer;

import com.cadre.common.utils.R;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.service.A79Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;

@RequestMapping({"/profess/a79"})
@RestController
/* loaded from: A79ImortController.class */
public class A79ImortController {
    @Autowired
    A79Service a79Ser;

    @RequestMapping({"downloadFile"})
    public void downloadFile(HttpServletResponse response, HttpServletRequest request) throws Exception {
        getExcel(new ClassPathResource("/excel\\家庭成员及重要社会关系信息采集表.xls"), "家庭成员及重要社会关系信息采集表" + DateUtil.dateToString(new Date(), "yyyyMMddHHmmss") + ".xlsx", response);
    }

    public static void getExcel(ClassPathResource cpr, String fileName, HttpServletResponse response) {
        try {
            response.setContentType("multipart/form-data");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gb2312"), "ISO-8859-1"));
            InputStream in = cpr.getInputStream();
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            byte[] buffer = new byte[2048];
            while (true) {
                int b = in.read(buffer);
                if (b != -1) {
                    out.write(buffer, 0, b);
                } else {
                    in.close();
                    out.flush();
                    out.close();
                    return;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping({"impExcel/{personId}"})
    @ResponseBody
    public R impExcel(@PathVariable String personId, MultipartHttpServletRequest request, HttpServletResponse response) {
        return R.ok(this.a79Ser.readExcelContentByList(request.getFile("file"), personId));
    }
}
